<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="/">
        <ol id="ord-list" style="margin-top:30px;" >
            <xsl:for-each select="//feed">
                <form method="post" action="updateFeedList.action">
                    <li class="item">
                        <input type="hidden" name="feedId">
                            <xsl:attribute name="value">
                                <xsl:value-of select="feedId"/>
                            </xsl:attribute>
                        </input>
                        <div class="actions">
                            <button class="edit" onclick="return validateSubmit(this.form)">
                                <span>Cập nhật</span>
                            </button>
                            <a onclick="return confirmDelete(this.form)"><xsl:attribute name="href">deleteFeedList.action?feedId=<xsl:value-of select="feedId"/></xsl:attribute>Xóa</a>
                        </div>
                        <table >
                            <tr>
                                <th>RSS Link:</th>
                                <td>
                                    <div class="show">
                                        <h3 class="h3">
                                            <xsl:value-of select="url" />
                                        </h3>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th>Tiêu đề(<font color="red">*</font>)</th>
                                <td>
                                    <div class="show">
                                        <p>
                                            <input type="text" size="70" name="title">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select="title"/>
                                                </xsl:attribute>
                                                <xsl:attribute name="onblur">check(1, 50, this, document.getElementById('title_help<xsl:value-of select="feedId"/>'))</xsl:attribute>
                                            </input>
                                        </p>
                                        <p>
                                            <span style="color:red">
                                                <xsl:attribute name="id">title_help<xsl:value-of select="feedId"/></xsl:attribute>
                                            </span>
                                        </p>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th>Mô tả(<font color="red">*</font>)</th>
                                <td>
                                    <p>
                                        <textarea name="description" rows="3" cols="10" style="resize:none">
                                            <xsl:attribute name="onblur">check(1, 100, this, document.getElementById('description_help<xsl:value-of select="feedId"/>'))</xsl:attribute>
                                            <xsl:value-of select="decription"/>
                                            
                                        </textarea>
                                    </p>
                                    <p>
                                        <span style="color:red" id="description_help">
                                            <xsl:attribute name="id">description_help<xsl:value-of select="feedId"/></xsl:attribute>
                                        </span>
                                    </p>
                                </td>
                            </tr>
                        </table>
                    </li>
                </form>
            </xsl:for-each>
        </ol>
        <xsl:comment><![CDATA[
    <script type="text/javascript">
        <xsl:text>
            function validateRegEx(regex, input, helpText, helpMessage) {
                if (!regex.test(input)) {
                    if (helpText != null) {
                        helpText.innerHTML = helpMessage;
                    }
                    return false;
                } else {
                    if (helpText != null) {
                        helpText.innerHTML = "";
                    }
                    return true;
                }
            }

            function validateNonEmpty(inputField, helpText) {
                return validateRegEx(/^[\S]+/, inputField.value, helpText, "Ký tự đầu tiên phải khác khoảng trắng.");
            }

            function validateLength(minLength, maxLength, inputField, helpText) {
                return validateRegEx(new RegExp("^.{" + minLength + "," + maxLength + "}$"),
                inputField.value, helpText, "Chỉ được nhập từ " + minLength + " tới " + maxLength + " ký tự");
            }

            function check(minLength, maxLength, inputField, helpText) {
                if (validateNonEmpty(inputField, helpText)) {
                    validateLength(minLength, maxLength, inputField, helpText)
                }
            }

            function validateSubmit(form) {
                if (validateNonEmpty(form["title"], form["title_help"]) &&
                    validateNonEmpty(form["description"], form["description_help"]) &&
                    validateLength(1, 50, form["title"], form["title_help"]) &&
                    validateLength(1, 100, form["description"], form["description_help"])) {

                    form.submit;
                } else {
                    alert("Nội dung không phù hợp. Xin kiểm tra lại.");
                }
            }
        </xsl:text>
    </script>
    ]]> 
        </xsl:comment>
    </xsl:template>

    

</xsl:stylesheet>
